<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/4/6 0006
 * Time: 17:11
 */
namespace app\modules\content\models;

use yii\db\ActiveRecord;

class VideoLog extends ActiveRecord
{
    public static function tableName()
    {
        return '{{%user_video_log}}';
    }

    public function rules()
    {
        return [
            // username and password are both required
            // [['student', 'cate', '', 'duration'], 'required'],

        ];
    }

    /**
     * [getVideoRecordTime 获取视频播放时长]
     * @Author don
     * @Date   2021-11-05
     * @return [type]     [description]
     */
    public static function getVideoRecordTime($classesId, $sdkId, $uid='')
    {
        if (!$uid) {
            return 0;
        } else {
            $res = self::find()->where(['classesId'=>$classesId, 'sdkId'=>$sdkId, 'uid'=>$uid, 'type'=>1])->asArray()->one();
            return $res?$res['record']:0;
        }
    }

    /**
     * [getTeacherVideoRecord 获取试听课播放记录]
     * @Author don
     * @Date   2021-11-09
     * @return [type]     [description]
     */
    public static function getTeacherVideoRecord($classesId, $uid='')
    {
        if (!$uid) {
            return 0;
        } else {
            $res = self::find()->where(['classesId'=>$classesId, 'type'=>2, 'uid'=>$uid])->asArray()->one();
            return $res?$res['record']:0;
        }
    }

    /**
     * @param $classesId
     * @param string $uid
     * @param $type
     * @return int
     */
    public static function getVideoRecord($classesId, $uid='',$type)
    {
        if (!$uid) {
            return 0;
        } else {
            $res = self::find()->where(['classesId'=>$classesId, 'type'=>$type, 'uid'=>$uid])->asArray()->one();
            return $res?$res['record']:0;
        }
    }
}